﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using NetLib;
using System.Collections.ObjectModel;

namespace MetaTracker.ViewModel
{
    class ExerciseServiceViewModel : TrackerBaseViewModel
    {
        #region Data and Properties



        public ObservableCollection<IExerciseResults> ExerciseData
        {
            get
            {
                return tracker.ExerciseData;
            }
        }

        public bool IsUsingFatSecret
        {
            get { return tracker.ExerciseService == ServiceEnum.FatSecret; }
        }
        public bool IsUsingFitbit
        {
            get { return tracker.FoodIntakeService == ServiceEnum.Fitbit; }
        }
        #endregion //Data and Properties

        #region Constructors

        internal ExerciseServiceViewModel()
        {
            tracker.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(tracker_PropertyChanged);
        }



        #endregion //Constructors

        #region Commands

        public ICommand RefreshCommand
        {
            get
            {
                return Commands.GetOrCreateCommand(
                    () => this.RefreshCommand,
                    (parameter) => DoRefreshCommand(parameter),
                    () => true);
            }
        }

        private void DoRefreshCommand(object parameter)
        {
            FetchExercise(true);
        }

        #endregion //Commands

        #region Methods
        void tracker_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            NotifyPropertyChanged(e.PropertyName);
            if (e.PropertyName == "ExerciseService")
            {
                NotifyPropertyChanged("IsUsingFatSecret");
                NotifyPropertyChanged("IsUsingFitbit");
            }
        }

        internal void InitializeData()
        {
            bool? gotExerciseResults;
            gotExerciseResults = FetchExercise();

        }

        internal bool? FetchExercise(bool forceUpdate = false)
        {
            switch (tracker.ExerciseService)
            {
                case ServiceEnum.None:
                    return false;
                case ServiceEnum.Withings:
                    return false;
                case ServiceEnum.FatSecret:
                    return tracker.FetchExerciseFatSecret(forceUpdate);
                case ServiceEnum.Fitbit:
                    return tracker.FetchExerciseFitbit(forceUpdate);
                default:
                    return false;
            }
        }


        #endregion //Methods
    }
}
